//
//  ViewController.m
//  03-按钮的基本使用
//
//  Created by wangneihan on 15/12/9.
//  Copyright © 2015年 wangneihan. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic,weak) IBOutlet UIButton *imgBtn;

-(CGRect)moveFrame:(NSString *) fangx withFrame:(CGRect) frame;

-(IBAction)up;

-(IBAction)down;

-(IBAction)left;

-(IBAction)right;

-(IBAction)big;

-(IBAction)small;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(CGRect)moveFrame:(NSString *) fangx withFrame:(CGRect) frame{
    
    if([fangx isEqualToString:@"up"])
    {
        frame.origin.y -= 10;
    }
    else if([fangx isEqualToString:@"down"])
    {
        frame.origin.y += 10;
    }
    if([fangx isEqualToString:@"left"])
    {
        frame.origin.x -= 10;
    }
    if([fangx isEqualToString:@"right"])
    {
        frame.origin.x += 10;
    }
    return  frame;
    
}


-(IBAction)up{
    //OC不能直接修改一个对象的结构体属性的成员
    //取出原来的frame
    self.imgBtn.frame = [self moveFrame:@"up" withFrame:self.imgBtn.frame];
}

-(IBAction)down{
    self.imgBtn.frame = [self moveFrame:@"down" withFrame:self.imgBtn.frame];
}

-(IBAction)left{
    self.imgBtn.frame = [self moveFrame:@"left" withFrame:self.imgBtn.frame];
}

-(IBAction)right{
    self.imgBtn.frame = [self moveFrame:@"right" withFrame:self.imgBtn.frame];
}

-(IBAction)big{
    NSLog(@"big");
    CGRect frame = self.imgBtn.bounds;
    frame.size.height += 10;
    frame.size.width += 10;
    self.imgBtn.bounds = frame;
}

-(IBAction)small{
    NSLog(@"small");
    CGRect frame = self.imgBtn.bounds;
    frame.size.height -= 10;
    frame.size.width -= 10;
    self.imgBtn.bounds = frame;
    
}

@end
